package com.qdsg.ysg.doctor.ui;

import android.widget.EditText;

import com.qdsg.ysg.doctor.util.AES128;
import com.qdsg.ysg.doctor.util.ToastUtil;
import com.rest.business.RestProxy;
import com.rest.response.BaseResponse;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import com.qdsg.ysg.doctor.R;
import com.qdsg.ysg.doctor.base.BaseActivity;

/**
 * Created by HP on 2018/8/31.
 */

public class UpdatePasswordActivity extends BaseActivity {

    @BindView(R.id.edt_password)
    EditText edt_password;
    @BindView(R.id.edt_newPassword)
    EditText edt_newPassword;
    @BindView(R.id.edt_newPassword2)
    EditText edt_newPassword2;

    @Override
    protected void initViews() {

    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.btn_save)
    void btn_save(){
        updatePassword();
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.aty_update_password;
    }


    private void updatePassword() {
        if(!edt_newPassword.getText().toString().equals(edt_newPassword2.getText().toString())){
            ToastUtil.showToast( mContext, "两次输入密码不一致" );
            return;
        }

        try {
            RestProxy.getInstance().updatePassword( AES128.encryptStringAES(edt_password.getText().toString(), "7t3e506jaa10xbd4"), AES128.encryptStringAES(edt_newPassword.getText().toString(), "7t3e506jaa10xbd4"), new Observer<BaseResponse>() {
                @Override
                public void onSubscribe(Disposable d) {

                }

                @Override
                public void onNext(BaseResponse baseResponse) {
                    ToastUtil.showToast( mContext, "操作成功" );
                    finish();
                }

                @Override
                public void onError(Throwable e) {
                    ToastUtil.onError( UpdatePasswordActivity.this, e);
                }

                @Override
                public void onComplete() {

                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
